package org.millioncall.yueyoga.admin.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.millioncall.openplatform.common.PaginateParams;
import org.millioncall.openplatform.common.PaginatedList;
import org.millioncall.openplatform.common.StartLimitPairImpl;
import org.millioncall.openplatform.dao.PreparedQuery;
import org.millioncall.yueyoga.admin.dao.BaseDao;
import org.millioncall.yueyoga.admin.dao.MemberLevelDAO;
import org.millioncall.yueyoga.admin.model.MemberLevel;
import org.springframework.stereotype.Repository;

@Repository
public class MemberLevelDAOImpl extends BaseDao implements MemberLevelDAO {

	@Override
	public PaginatedList<MemberLevel> findPage(int start, int limit) {
		try {
			PreparedQuery<MemberLevel> pq = this.getPagableSqlSessionTemplate()
					.findAll("findMemberLevelPage");
			PaginatedList<MemberLevel> pl = pq.list(new PaginateParams(
					new StartLimitPairImpl(start, limit)));
			return pl;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@Override
	public MemberLevel findById(Integer id) {
		return this.getPagableSqlSessionTemplate().selectOne("getMemberLevelByID",id);
	}

	@Override
	public int update(Map<String, Object> map) {
		return this.getPagableSqlSessionTemplate().insert("updateMemberLevel",
				map);
	}

	@Override
	public int save(Map<String, Object> map) {
		return this.getPagableSqlSessionTemplate().insert("saveMemberLevel",
				map);
	}

	@Override
	public void deleteByIds(Integer[] deids) {
		Map<String, Object> map = new HashMap<String, Object>();
		for (int i = 0; i < deids.length; i++) {
			map.put("id", deids[i]);
			this.getPagableSqlSessionTemplate()
					.insert("deleteMemberLevel", map);
		}
	}

	@Override
	public List<MemberLevel> getMemberLevelByEnable() {
		List<MemberLevel> pq = this.getPagableSqlSessionTemplate().selectList("getMemberLevelByEnable");
		return pq;
	}
	
}
